﻿<BadHabit_Factory_Controls:GenericPanel
    x:Class="BadHabit.Factory.Controls.RiskPanel"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:BadHabit_Factory_Controls="clr-namespace:BadHabit.Factory.Controls"        
    xmlns:BadHabit_Factory_Converters="clr-namespace:BadHabit.Factory.Converters"  
    xmlns:BadHabit_WPFTools="clr-namespace:BadHabit.WPFTools;assembly=BadHabit.WPFTools"       
    xmlns:BadHabit_WPFTools_Converters="clr-namespace:BadHabit.WPFTools.Converters;assembly=BadHabit.WPFTools"
    xmlns:Microsoft_Toolkit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
    xmlns:BadHabit_Factory="clr-namespace:BadHabit.Factory"
    xmlns:Factory_Core="clr-namespace:BadHabit.Factory;assembly=FactoryCore"    
    
    
           
    
    xmlns:props="clr-namespace:BadHabit.Factory.Properties"
    
    HorizontalAlignment="Stretch"
    VerticalAlignment="Stretch"
    Background="Transparent"
      
    >

    <BadHabit_Factory_Controls:GenericPanel.CommandBindings>
        <CommandBinding Command="ApplicationCommands.Save" CanExecute="Save_CanExecute" Executed="Save_Executed"/>
    </BadHabit_Factory_Controls:GenericPanel.CommandBindings>



    <BadHabit_Factory_Controls:GenericPanel.Resources>

        <DataTemplate x:Key="RiskImpactTemplate">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" Background="Transparent">
                <Image VerticalAlignment="Center" Style="{StaticResource RiskImpactImage}" Width="32" Height="32"/>                
                <TextBlock VerticalAlignment="Center" Margin="5,0,0,0" Text="{Binding ., Converter={StaticResource LocalizeConverter}}"/>                                    
            </StackPanel>            
        </DataTemplate>
        <DataTemplate x:Key="RiskImpactSelectedTemplate">            
            <Image   VerticalAlignment="Center" HorizontalAlignment="Center" Style="{StaticResource RiskImpactImage}" Width="32" Height="32"/>            
        </DataTemplate>

    </BadHabit_Factory_Controls:GenericPanel.Resources>
    
    <Grid x:Name="ContentPanel" VerticalAlignment="Stretch">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>           
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <DockPanel Grid.Row="0">
            <ToolBar DockPanel.Dock="Left" ToolBarTray.IsLocked="True" Height="60"  >
            </ToolBar>
            <Button
                        x:Name="commitButton"
                        DockPanel.Dock="Right"
                        Style="{StaticResource CommitButton}"
                        Command="ApplicationCommands.Save"
                        HorizontalAlignment="Right" 
                        Margin="5" />
        </DockPanel>

        <Border
                Grid.Row="1"                  
                Style="{StaticResource RoundBorder}">


            <BadHabit_WPFTools:DataGrid
                
                BadHabit_WPFTools:RoleChecker.RequiredEditRole="SCRUM_MASTER"                                
                Grid.Row="1"
                
                UseNavigationExtensions="True"
                
                x:Name="riskDataGrid"                
                
                VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                ItemsSource="{Binding Risk}"
                AutoGenerateColumns="False"
                
                InitializingNewItem="riskDataGrid_InitializingNewItem"
                
                        
                Margin="2,2,2,2"                
                GridLinesVisibility="Horizontal"
                HorizontalGridLinesBrush="{StaticResource WaterMarkBrush}"
                RowHeaderWidth="0"
                RowHeight="60"
                                
                BorderThickness="0,0,0,0"                                
                SelectionMode="Extended"
                SelectionUnit="FullRow"
        
                
                ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                ScrollViewer.VerticalScrollBarVisibility="Auto">

                <Microsoft_Toolkit:DataGrid.Columns>

                    <Microsoft_Toolkit:DataGridTemplateColumn
                        Header="{x:Static props:Resources.Impact}"                        
                        CanUserResize="False"  
                        CellStyle="{StaticResource CenterAlignCellStyle}"
                        Width="60">
                        <Microsoft_Toolkit:DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <BadHabit_WPFTools:ComboBox                                              
                                        Style="{StaticResource ClickOnComboBox}"
                                        Background="Transparent"                                        
                                        HorizontalContentAlignment="Center" VerticalContentAlignment="Center"                                                                                                                        
                                        SelectedValue="{Binding Impact, Converter={StaticResource EnumConverter}, ConverterParameter={x:Type Factory_Core:RiskImpact}}"   
                                        ItemsSource="{Binding Source={StaticResource RiskImpactList}}"
                                        ItemTemplate="{StaticResource RiskImpactTemplate}"
                                        SelectedItemTemplate="{StaticResource RiskImpactSelectedTemplate}"/>
                            </DataTemplate>
                        </Microsoft_Toolkit:DataGridTemplateColumn.CellEditingTemplate>
                        <Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Image                                     
                                    DataContext="{Binding Impact, Converter={StaticResource EnumConverter}, ConverterParameter={x:Type Factory_Core:RiskImpact}}"
                                    ToolTip="{Binding ., Converter={StaticResource LocalizeConverter}}"
                                    VerticalAlignment="Center" HorizontalAlignment="Center" Style="{StaticResource RiskImpactImage}" Width="32" Height="32"/>
                            </DataTemplate>
                        </Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>
                        
                    </Microsoft_Toolkit:DataGridTemplateColumn>
                    
                    <Microsoft_Toolkit:DataGridTemplateColumn
                        Header="{x:Static props:Resources.Probability}"                        
                        CanUserResize="False"                         
                        Width="100">
                        <Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="10,0,0,0">
                                    <Image 
                                    DataContext="{Binding Probability, Converter={StaticResource EnumConverter}, ConverterParameter={x:Type Factory_Core:RiskImpact}}"                                    
                                    HorizontalAlignment="Center"                                    
                                    ToolTip="{Binding ., Converter={StaticResource LocalizeConverter}}"
                                    VerticalAlignment="Bottom" Style="{StaticResource RiskImpactImage}" Width="32" Height="32"/>
                                    <Image                                         
                                    DataContext="{Binding PreviousBaselineProbability, Converter={StaticResource EnumConverter}, ConverterParameter={x:Type Factory_Core:RiskImpact}}"                                    
                                    ToolTip="{Binding ., Converter={StaticResource LocalizeConverter}}"
                                    HorizontalAlignment="Center"                                    
                                    VerticalAlignment="Bottom" Style="{StaticResource RiskImpactImage}" Width="16" Height="16"/>
                                </StackPanel>                                
                            </DataTemplate>
                        </Microsoft_Toolkit:DataGridTemplateColumn.CellTemplate>
                        <Microsoft_Toolkit:DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="4,0,0,0">
                                    <BadHabit_WPFTools:ComboBox                 
                                        Style="{StaticResource ClickOnComboBox}"                                                                
                                        HorizontalContentAlignment="Center" VerticalContentAlignment="Center"                                                                                                                        
                                        SelectedValue="{Binding Probability, Converter={StaticResource EnumConverter}, ConverterParameter={x:Type Factory_Core:RiskProbability} }"   
                                        ItemsSource="{Binding Source={StaticResource RiskProbabilityList}}"
                                        ItemTemplate="{StaticResource RiskImpactTemplate}"
                                        SelectedItemTemplate="{StaticResource RiskImpactSelectedTemplate}"
                                        
                                        />
                                    <Image 
                                    DataContext="{Binding PreviousBaselineProbability, Converter={StaticResource EnumConverter}, ConverterParameter={x:Type Factory_Core:RiskImpact}}"                                    
                                    HorizontalAlignment="Center"
                                    VerticalAlignment="Bottom"
                                    Style="{StaticResource RiskImpactImage}" Width="16" Height="16"
                                        
                                        />
                                </StackPanel>
                            </DataTemplate>
                        </Microsoft_Toolkit:DataGridTemplateColumn.CellEditingTemplate>
                    </Microsoft_Toolkit:DataGridTemplateColumn>



                    <Microsoft_Toolkit:DataGridTextColumn
                        Header="{x:Static props:Resources.Risk}"
                        Width="*"
                        TextBlock.FontSize="{StaticResource NeedToSeeFontSize}"                       
                        
                        ElementStyle="{StaticResource NeedToSeeTextElementStyle}"
                        Binding="{Binding RiskName}" >
                        <Microsoft_Toolkit:DataGridTextColumn.EditingElementStyle>
                            <Style TargetType="TextBox" BasedOn="{StaticResource NeedToSeeTextEditingElementStyle}">
                                <Setter Property="MaxLength" Value="255"/>
                            </Style>
                        </Microsoft_Toolkit:DataGridTextColumn.EditingElementStyle>
                    </Microsoft_Toolkit:DataGridTextColumn>


                    <Microsoft_Toolkit:DataGridTextColumn
                        Header="{x:Static props:Resources.Actions}"
                        Width="*"
                        TextBlock.FontSize="{StaticResource NeedToSeeFontSize}"                       
                        
                        ElementStyle="{StaticResource NeedToSeeTextElementStyle}"
                        Binding="{Binding Actions}" >
                        <Microsoft_Toolkit:DataGridTextColumn.EditingElementStyle>
                            <Style TargetType="TextBox" BasedOn="{StaticResource NeedToSeeTextEditingElementStyle}">
                                <Setter Property="MaxLength" Value="500"/>
                            </Style>
                        </Microsoft_Toolkit:DataGridTextColumn.EditingElementStyle>
                    </Microsoft_Toolkit:DataGridTextColumn>

                    <Microsoft_Toolkit:DataGridTextColumn
                        Header="{x:Static props:Resources.Created_at}"
                        Width="Auto"
                        IsReadOnly="True"
                        Binding="{Binding CreateDate, StringFormat='{}{0:d}'}"/>
                        
                    

                </Microsoft_Toolkit:DataGrid.Columns>

            </BadHabit_WPFTools:DataGrid>
            
            


        </Border>


    </Grid>
</BadHabit_Factory_Controls:GenericPanel>
